<!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<html>
<title>Nav 3</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
<link rel="stylesheet" href="../stylesheets/style.css">
<script type="text/javascript" src="javascripts/base.js"></script>
<script type="text/javascript" src="http://g.alicdn.com/ilw/ding/0.7.3/scripts/dingtalk.js"></script>
<script type="text/javascript">

    dd.config({
        /**
         * 配置参数
         */
    });

    dd.ready(init);

    function init() {
        log.i('runtimeready');
    	dd.biz.navigation.setMenu({
    		backgroundColor : "#ADD8E6",
    		items : [
    			{
    				id:"此处可以设置帮助",//字符串
    			// "iconId":"file",//字符串，图标命名
    			  text:"帮助"
    			}
    			,
    			{
    				"id":"2",
    			"iconId":"photo",
    			  "text":"我们"
    			}
    			,
    			{
    				"id":"3",
    			"iconId":"file",
    			  "text":"你们"
    			}
    			,
    			{
    				"id":"4",
    			"iconId":"time",
    			  "text":"他们"
    			}
    		],
    		onSuccess: function(data) {
    			alert(JSON.stringify(data));

    		},
    		onFail: function(err) {
    			alert(JSON.stringify(err));
    		}
    	});


        document.addEventListener('pause', function() {
            log.i('3 pause');
        });

        document.addEventListener('resume', function() {
            log.i('3 resume');

            dd.ui.nav.getCurrentId({
                onSuccess: function(data) {
                    log.i('current nav id: ' + JSON.stringify(data));
                },
                onFail: function(err) {
                    log.e(JSON.stringify(err));
                }
            });

            dd.runtime.message.fetch({
                onSuccess: function(data) {
                    log.i('fetch message success: ' + JSON.stringify(data));

                    if (data && data.length > 0) {
                        var reply = data[0].from;

                        dd.runtime.message.post({
                            to: [reply],
                            content: {
                                response: 'message received in 3'
                            },
                            onSuccess: function () {
                                log.i('respond');
                            },
                            onFail: function (err) {
                                log.e(JSON.stringify(err));
                            }
                        });
                    }
                },
                onFail: function(err) {
                    log.e('fetch message err: ' + JSON.stringify(err));
                }
            });
        });

        document.addEventListener('pullToRefresh', function(ev) {
            log.i('pullToRefresh');
        });

        dd.ui.pullToRefresh.enable();

        dd.biz.navigation.setTitle({
            title: 'runtime3',
            onSuccess: function(data) {
                log.i('set title 3');
            },
            onFail: function(err) {
                log.e(JSON.stringify(err));
            }
        });

        dd.biz.navigation.setRight({
            show: true,
            control: true,
            showIcon: false,
            text: '3',
            onSuccess : function(result) {
                log.i('set right 3');
            },
            onFail : function(err) {
                log.e(JSON.stringify(err));
            }
        });
    }

    function back() {
        dd.biz.navigation.back({
            onSuccess: function() {
                log.i('3 goback');
            },
            onFail: function(err) {
                log.e('back err: ' + JSON.stringify(err));
            }
        });
    }

</script>
</head>
<body>
<h2>Nav 3</h2>
<div><button onclick="back()">Back</button></div>
<div class="clear-float"/>
<div id="log"></div>
</body>
</html>